﻿// <copyright file="StormBuilder.cs" company="City of Portland, BES-ASM">
// </copyright>
// <summary>StormBuilder class</summary>

namespace BESASM.EMGAATS.DataAccess
{
  using System;
  using System.Collections.Generic;
  using System.IO;
  using System.Linq;
  using System.Text;
  using System.Threading.Tasks;
  using SystemWrapper;
  using BusinessClasses;

  /// <summary>
  /// Provides utility methods to build Storm objects
  /// </summary>
  public class StormBuilder
  {
    /// <summary>
    /// Creates a synthetic (design) storm for use in a simulation
    /// </summary>
    /// <param name="filename">The path to the storm file; follows a specific format</param>
    /// <param name="timeStepSec">Time step to use in seconds</param>
    /// <returns>A design/synthetic storm</returns>
    public static Storm BuildSyntheticStorm(string filename, int timeStepSec)
    {
      SystemWrapper.IO.IStreamReaderWrap sourceFile = 
        new SystemWrapper.IO.StreamReaderWrap(filename);
      IRainSource source = new SWMM5TextRainSource(sourceFile);
      Storm synthStorm = new Storm(source);
      synthStorm.TimeStepSec = timeStepSec;
      return synthStorm;
    }

    /// <summary>
    /// Creates an actual storm with actual raingages for use in a simulation
    /// </summary>
    /// <param name="startDate">The starting date to retrieve</param>
    /// <param name="endDate">The ending date to retrieve</param>
    /// <param name="timeStepSec">Time step to use in seconds</param>
    /// <returns>A storm with actual gages</returns>
    public static Storm BuildActualStorm(DateTime startDate, DateTime endDate, int timeStepSec)
    {
      IRainSource source = new NeptuneDBActualRainSource(startDate, endDate, timeStepSec);
      Storm actualStorm = new Storm(source);
      actualStorm.TimeStepSec = timeStepSec;
      return actualStorm;
    }

    /// <summary>
    /// Creates an actual storm with virtual gages for use in a simulation
    /// </summary>
    /// <param name="startDate">The starting date to retrieve</param>
    /// <param name="endDate">The ending date to retrieve</param>
    /// <param name="timeStepSec">Time step to use in seconds</param>
    /// <param name="virtualRGLocations">List of points for creating raingages</param>
    /// <returns>A storm with virtual gages</returns>
    public static Storm BuildVirtualStorm(
      DateTime startDate, 
      DateTime endDate, 
      int timeStepSec,
      Dictionary<int, IPoint> virtualRGLocations)
    {
      IRainSource source = 
        new NeptuneDBVirtualRainSource(startDate, endDate, timeStepSec, virtualRGLocations);
      Storm virtualStorm = new Storm(source);
      virtualStorm.TimeStepSec = timeStepSec;
      return virtualStorm;
    }
  }
}
